package com.example.testanimation;

import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.Switch;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class setting extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Compiler EdgeToEdge = null;
        EdgeToEdge.enable();
        setContentView(R.layout.activity_setting);
        // 寻找Switch和LinearLayout
        Switch switch1 = findViewById(R.id.switch1);
        LinearLayout listItem1 = findViewById(R.id.list_item1);

// 设置Switch的监听器
        switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                // 根据Switch的状态改变LinearLayout的可见性
                if (isChecked) {
                    // 如果Switch打开，显示list_item1
                    listItem1.setVisibility(View.VISIBLE);
                } else {
                    // 如果Switch关闭，隐藏list_item1
                    listItem1.setVisibility(View.GONE);
                }
            }
        });

    }

    public void tuichu(View view) {
        // 显示退出登录确认对话框
        new AlertDialog.Builder(this)
                .setTitle("退出登录")
                .setMessage("你确定要退出登录吗？")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        Intent intent = new Intent(setting.this, Login.class); // 确保类名正确
                        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(intent);

                        // 结束当前Activity
                        finishAffinity();
                    }
                })
                .setNegativeButton("取消", null) // 设置取消按钮，点击后对话框消失不做操作
                .show();
    }
    //跳转到修改密码
    public void gotoUpdate(View view)
    {
        Intent intent = new Intent(setting.this, updatePassword.class);
        startActivity(intent);
    }
    //跳转到添加学生页面
    public void addStudent(View view)
    {
        Intent intent = new Intent(setting.this, Addstudent.class);
        startActivity(intent);

    }

    public void addclass(View view)
    {
        Intent intent = new Intent(setting.this, AddClass.class);
        startActivity(intent);

    }
    //  //跳转到添加课程页面
    public void Add_Class(View view)
    {
        Intent intent = new Intent(setting.this, AddClass.class);
        startActivity(intent);
    }
}